package com.corticon.dialogs.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;


/**
 * ResponseType entity.
 * 
 * @author Lifan Yang
 */
@Entity
@Table(name = "q_responsetype")
public class ResponseType extends AuditableEntity implements Serializable {

    private Long responseTypeId;
    private String id;
    private String name;
    private UiControl uicontrol;
    private DataType dataType;
    private DataValidation dataValidation;
    private Units untis;
    private Frequency frequency;
    private Boolean dynamic;
    private Set<ResponseEntry> responseEntries = new HashSet<ResponseEntry>();

    public ResponseType() {
    }

    public ResponseType(UiControl uicontrol, DataType dataType, DataValidation dataValidation,
        Units untis, Frequency frequency, Boolean dynamic) {
        this.uicontrol = uicontrol;
        this.dataType = dataType;
        this.dataValidation = dataValidation;
        this.untis = untis;
        this.frequency = frequency;
        this.dynamic = dynamic;
    }

    @Id
    @SequenceGenerator(name = "q_responsetype_id_seq",
            sequenceName = "q_responsetype_id_seq",
            allocationSize = 1, initialValue = 1) // Set allocationSize and initialValue
                                                  // to let sequence increment following DB.)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "q_responsetype_id_seq")
    @Column(name = "q_responsetype_id", columnDefinition = "integer")
    public Long getResponseTypeId() {
        return this.responseTypeId;
    }

    public void setResponseTypeId(Long responseTypeId) {
        this.responseTypeId = responseTypeId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "uicontrolassoc_code_oid")
    public UiControl getUicontrol() {
        return this.uicontrol;
    }

    public void setUicontrol(UiControl uicontrol) {
        this.uicontrol = uicontrol;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "datatypeassoc_code_oid")
    public DataType getDataType() {
        return this.dataType;
    }

    public void setDataType(DataType dataType) {
        this.dataType = dataType;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "datavalidationassoc_code_oid")
    public DataValidation getDataValidation() {
        return this.dataValidation;
    }

    public void setDataValidation(DataValidation dataValidation) {
        this.dataValidation = dataValidation;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "unitsassoc_code_oid")
    public Units getUnits() {
        return this.untis;
    }

    public void setUnits(Units units) {
        this.untis = units;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "frequencyassoc_code_oid")
    public Frequency getFrequency() {
        return this.frequency;
    }

    public void setFrequency(Frequency frequency) {
        this.frequency = frequency;
    }

    /**
     * dynamic is a reserved keyword in SQL 99
     *
     * @return
     */
    //    @Column(name = "_DYNAMIC")
    @Column(name = "dynamic")
    public Boolean getDynamic() {
        return this.dynamic;
    }

    public void setDynamic(Boolean dynamic) {
        this.dynamic = dynamic;
    }

    @Column(name = "id", length = 256)
    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "name", length = 256)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(mappedBy = "responseType", cascade = CascadeType.ALL)
    public Set<ResponseEntry> getResponseEntries() {
        return responseEntries;
    }

    public void setResponseEntries(Set<ResponseEntry> responseEntries) {
        this.responseEntries = responseEntries;
    }
}